/** 
* @author : 褚国强
* @date 创建时间：2021年11月17日 上午10:07:27 
* @version 1.0
*/
package com.bsoft.project.service;

import java.io.File;
import java.util.HashMap;
import java.util.Random;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.LineIterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bsoft.project.mapper.RsfComlfsServiceMapper;
import com.bsoft.project.model.MaxValueVo;
import com.bsoft.project.model.MlcxDataVo;
import com.bsoft.project.model.MlcxVo;
import com.bsoft.project.model.MlcxVoExcel;
import com.bsoft.project.model.ZfblDataVo;
import com.bsoft.project.model.ZfblVo;
import com.bsoft.project.model.ZfblVoExcela;
import com.bsoft.project.utils.Decompressing;
import com.bsoft.project.utils.ExcelListener;
import com.bsoft.project.utils.PinyinUtil;
import com.bsoft.project.utils.RSFRequestJsonUtil;
import com.bsoft.project.utils.RsfComIfsService;
import com.bsoft.project.utils.StringUtils;
import com.bsoft.project.utils.ZfblExcelListener;

/** 
* @author : 褚国强
* @date 创建时间：2021年11月17日 上午10:07:27 
* @Description: TODO
* @version 1.0 
* @parameter 
* @since 
* @return 
*/
@Service
public class RsfComlfServiceSvc {

	@Value("${rsf-comlf.requestIp}") private String requestIp;
	@Value("${rsf-comlf.fileQueryUrl}") private String fileQueryUrl;
	@Value("${rsf-comlf.downLoadUrl}") private String downLoadUrl;
	@Value("${rsf-comlf.key}") private String key;
	@Value("${rsf-comlf.secret}") private String secret;
	@Value("${rsf-comlf.zfblDefUrl}") private String zfblDefUrl;
	@Value("${rsf-comlf.ylmlcxDefUrl}") private String ylmlcxDefUrl;
	
	private String baseRequestIp;
	private String requestFileQueryUrl;
	private String requestUrl;
	private String requestKey;
	private String requestSecret;
	private String zfblUrl;
	private Long pageSize;
	private String admdvs;
	private String updateDate;
	private String ylmlcxUrl;
	
	@Autowired
    private RsfComlfsServiceMapper rsfComlfsServiceMapper;
	
	private final Logger logger = LoggerFactory.getLogger(RsfComlfServiceSvc.class);
	
	
	public void init(int jgid) throws Exception {
		baseRequestIp = this.getXtCsz("GJYB_URL", requestIp, "国家医保交易URL",jgid);
		requestFileQueryUrl = baseRequestIp + this.getXtCsz("JAVA_RSF_QUERY_URL", fileQueryUrl, "Java 医疗目录下载，查询文件请求地址",jgid);
		requestUrl = baseRequestIp + this.getXtCsz("JAVA_RSF_DOWN_URL", downLoadUrl, "Java 医疗目录下载，zip文件请求地址",jgid);
		requestKey = this.getXtCsz("GJYB_KEY", key, "国家医保交易KEY",jgid);
		requestSecret = this.getXtCsz("GJYB_SECRET", secret, "国家医保交易SECRET",jgid);
		zfblUrl = baseRequestIp + this.getXtCsz("JAVA_RSF_ZFBL_URL", zfblDefUrl, "Java ,自付比例查询请求 URL",jgid);
		pageSize = Long.valueOf(this.getXtCsz("JAVA_RSF_PAGESIZE", "1000", "Java ,自付比例  每页大小",jgid));
		admdvs = this.getXtCsz("JAVA_RSF_ADMDVS", "330483", "Java ,自付比例  区域号",jgid);
		updateDate = this.getXtCsz("JAVA_RSF_UPDATEDATE", "2000-01-01", "Java ,自付比例  默认开始时间",jgid);
		ylmlcxUrl = baseRequestIp + this.getXtCsz("JAVA_RSF_MLCX_URL", ylmlcxDefUrl, "Java ,医疗目录查询URL",jgid);
	}
	
	/** 
	* @author : 褚国强
	* @date 创建时间：2021年12月17日 上午10:07:27 
	* @Description:  自动查询最大版本号，去循坏查询
	* @version 1.0 
	* @parameter 
	* @since 
	* @return 
	*/
	public HashMap<String, Object> rsfComIfsServiceLoop(HashMap<String,Object> param) throws Exception {
		HashMap<String, Object> returnMap = new HashMap<String, Object>();		
		returnMap.put("code", 200);
		returnMap.put("message", "SUCCESS!");
		
		String parStr = JSON.toJSONString(param);
		JSONObject queryJsonObject = JSONObject.parseObject(parStr);
		String infno = param.get("infno").toString();
		
//		baseRequestIp = this.getXtCsz("GJYB_URL", requestIp, "国家医保交易URL");
//		requestFileQueryUrl = baseRequestIp + this.getXtCsz("JAVA_RSF_QUERY_URL", fileQueryUrl, "Java 医疗目录下载，查询文件请求地址");
//		requestUrl = baseRequestIp + this.getXtCsz("JAVA_RSF_DOWN_URL", downLoadUrl, "Java 医疗目录下载，zip文件请求地址");
//		requestKey = this.getXtCsz("GJYB_KEY", key, "国家医保交易KEY");
//		requestSecret = this.getXtCsz("GJYB_SECRET", secret, "国家医保交易SECRET");
//		zfblUrl = baseRequestIp + this.getXtCsz("JAVA_RSF_ZFBL_URL", zfblDefUrl, "Java ,自付比例查询请求 URL");
		
		String returnStr = RsfComIfsService.sentServiceJson(requestFileQueryUrl+infno, parStr, requestKey, requestSecret,true);
		if(returnStr.contains("已经是最新数据")){
			returnMap.put("data", "已经是最新数据");
		}else{
			JSONObject returnJson = JSONObject.parseObject(returnStr);
			if(StringUtils.isNotEmpty((returnJson.getString("err_msg")))){
				throw new Exception(returnJson.getString("err_msg"));
			}
			returnMap.put("data", RSFRequestJsonUtil.getDownLoadJson(queryJsonObject, returnJson));
		}
		
		return returnMap;
	}
	/** 
	* @author : 褚国强
	* @date 创建时间：2021年12月17日 
	* @Description:  目录zip 下载解析
	* @version 1.0 
	* @parameter 
	* @since 
	* @return 
	*/
	@Transactional(rollbackFor = Exception.class)
	public HashMap<String, Object> rsfComIfsService(String parStr) throws Exception {
		
//		String parStr = JSON.toJSONString(param);
		JSONObject jsonObject = JSONObject.parseObject(parStr);
		String fileQuryNo = jsonObject.getJSONObject("input").getJSONObject("fsDownloadIn").getString("file_qury_no");
		
		File fileDir = new File("\\gjyb_down"); 
		if(!fileDir.exists()){
			fileDir.mkdirs(); 
		}
		String type = jsonObject.getString("download_type"); // 下载类型
		long beginTime = System.currentTimeMillis();
		
		Random random = new Random(); // 防止狗屎性的同时请求相同名称
		
		String fileName = jsonObject.getString("fixmedins_code") + "_" + type + "_" + System.currentTimeMillis()+ "_" + random.nextInt(1000) + ".zip";
		
		String filePath = "\\gjyb_down\\" + fileName;
		
		RsfComIfsService.sentService(requestUrl, parStr, filePath, requestKey, requestSecret);
		
		HashMap<String, Object> returnMap = new HashMap<String, Object>();
		
		returnMap.put("code", 200);
		returnMap.put("message", "SUCCESS!");
		returnMap.put("type", type);
		returnMap.put("fileQuryNo", fileQuryNo);
		
		logger.info("---------------------------- read file ");
		
		String zipPath = Decompressing.zipUncompress(filePath);
//		Decompressing.readFiles(zipPath);
		String maxVerStr =  readFiles(zipPath,type,fileQuryNo,fileName,jsonObject);
//		readFiles("D:\\gjyb_down\\H33048300087_1637223928670");
		returnMap.put("maxVerStr", maxVerStr);
		long endTime = System.currentTimeMillis();
		logger.info("---------------------------- 总时间（毫秒）：" + (endTime - beginTime));
		return returnMap;
	}
	/**
	 * 解压文件夹解析
	*/
	private String readFiles(String inputFile,String type,String fileQuryNo,String fileName,JSONObject jsonObject) throws Exception {
		File srcFile = new File(inputFile);
		MaxValueVo maxVo = new MaxValueVo();
		if (srcFile.isDirectory()) {
			File next[] = srcFile.listFiles();
			for (int i = 0; i < next.length; i++) {
				logger.info(next[i].getName());
				if (!next[i].isDirectory()) {

					LineIterator lineIterator = FileUtils.lineIterator(next[i], "utf-8");
					long beginTime = System.currentTimeMillis();
//					List<String[]> arr1 = new ArrayList<>();
					int lineNum = 0;
					while (lineIterator.hasNext()) {
						String result = lineIterator.next();
						String[] arr = result.split("\t");
						try{
							maxVo = insertOracle(arr,type,maxVo.getMaxValStr(),maxVo.getMaxVal());
//							if("1301".equals(type)||"1302".equals(type)||"1305".equals(type)||"1306".equals(type)){
//								insertUpdateZFBL(arr[0],jsonObject);
//							}
						}catch(Exception e){
							for(int a=0;a<arr.length;a++){
								logger.error("解析失败---------"+ (a+1) +"--------" + arr[a]);
							}
							throw new Exception(e);
						}
//						if(lineNum == 5000){
//							break;
//						}
						if(lineNum%5000 == 0){
							logger.info("已解析-----------------" + lineNum);
							
						}
						lineNum ++;
					}
					
					if(!"".equals(maxVo.getMaxValStr())){
						HashMap<String,Object> param = new HashMap<String,Object>();
						param.put("fileQuryNo", fileQuryNo);
						param.put("fileName", fileName);
						param.put("type", type);
						param.put("maxVer", maxVo.getMaxVal());
						updateDownloadVersion(param);
					}
					logger.info("总解析-----------------" + lineNum);
					long endTime = System.currentTimeMillis();
					logger.info("" + (endTime - beginTime));


				}
			}
			
		}
		return maxVo.getMaxValStr();
	}
	
	private MaxValueVo insertOracle(String[] arr,String type,String maxVerStr,long maxVer){
		MaxValueVo maxVo = new MaxValueVo();
		if(type.equals("1301")){   // --------------西药中成药目录下载	
			if(StringUtils.isNotEmpty(arr[78]) && "1".equals(arr[78])){   //有效标志为1才插入
				if(isExists("gjyb_xyzcyml","ylmlbm",arr[0]) == 0){
					if(arr[18].length()>2000){
						arr[18] = arr[18].substring(0, 2000/3);								
					}
					rsfComlfsServiceMapper.insertYbmlStr(getPinYinArr(arr,7));					
				}
			}
			if(StringUtils.isNotEmpty(arr[83])){   // 取ver_name
				long bbh = getBBH(arr[83]);
				if(bbh > maxVer){
					maxVer = bbh;
					maxVerStr = arr[83];
				}					
			}
		}else if(type.equals("1302")){  // --------------中药饮片目录下载
			if(StringUtils.isNotEmpty(arr[13]) && "1".equals(arr[13])){   //有效标志为1才插入
				if(isExists("gjyb_zyypml","ylmlbm",arr[0]) == 0){
					rsfComlfsServiceMapper.insertZyypml(getPinYinArr(arr,1));	
				}
			}
			if(StringUtils.isNotEmpty(arr[18])){     // 取ver_name
				long bbh = getBBH(arr[18]);
				if(bbh > maxVer){
					maxVer = bbh;
					maxVerStr = arr[18];
				}					
			}
		}else if(type.equals("1303")){  // --------------医疗机构制剂目录下载		
			if(StringUtils.isNotEmpty(arr[64]) && "1".equals(arr[64])){   //有效标志为1才插入
				if(isExists("gjyb_yljgzjml","ylmlbm",arr[0]) == 0){
					if(arr[77].length()>2000){
						arr[77] = arr[77].substring(0, 2000/3);								
					}
					rsfComlfsServiceMapper.insertYljgzjml(getPinYinArr(arr,1));
				}
			}
			if(StringUtils.isNotEmpty(arr[71])){      // 取ver_name
				long bbh = getBBH(arr[71]);
				if(bbh > maxVer){
					maxVer = bbh;
					maxVerStr = arr[71];
				}					
			}
		}else if(type.equals("1304")){  // --------------民族药品目录查询
			
		}else if(type.equals("1305")){  // --------------医疗服务项目目录下载
			if(StringUtils.isNotEmpty(arr[6]) && "1".equals(arr[6])){   //有效标志为1才插入
				if(isExists("gjyb_ybylfwml","ylmlbm",arr[0]) == 0){
					rsfComlfsServiceMapper.insertYlfwxmml(getPinYinArr(arr,9));	
				}
			}
			if(StringUtils.isNotEmpty(arr[15])){      // 取ver_name
				long bbh = getBBH(arr[15]);    
				if(bbh > maxVer){
					maxVer = bbh;
					maxVerStr = arr[15];
				}					
			}
		}else if(type.equals("1306")){  // --------------医用耗材目录下载	
			if(StringUtils.isNotEmpty(arr[67]) && "1".equals(arr[67])){   //有效标志为1才插入
				if(isExists("gjyb_ybhcml","ylmlbm",arr[0]) == 0){
					if(arr[23].length()>2000){
						arr[23] = arr[23].substring(0, 2000/3);								
					}
					rsfComlfsServiceMapper.insertYyhcml(getPinYinArr(arr,4));
				}
			}
			if(StringUtils.isNotEmpty(arr[70])){      // 取ver_name
				long bbh = getBBH(arr[70]);
				if(bbh > maxVer){
					maxVer = bbh;
					maxVerStr = arr[70];
				}					
			}
		}else if(type.equals("1307")){  // --------------疾病与诊断目录下载
			if(StringUtils.isNotEmpty(arr[18]) && "1".equals(arr[18])){   //有效标志为1才插入
				if(isExists("gjyb_xyjbzdml","xyjbzdid",arr[0]) == 0){
					rsfComlfsServiceMapper.insertJbyzdml(getPinYinArr(arr,11));
				}
			}
			if(StringUtils.isNotEmpty(arr[22])){     // 取ver
				long bbh = getBBH(arr[22]);
				if(bbh > maxVer){
					maxVer = bbh;
					maxVerStr = arr[22];
				}					
			}
		}else if(type.equals("1308")){  // --------------手术操作目录下载
			if(StringUtils.isNotEmpty(arr[18]) && "1".equals(arr[18])){   //有效标志为1才插入
				if(isExists("gjyb_ssczml","ssbzmlid",arr[0]) == 0){
					rsfComlfsServiceMapper.insertSsczml(getPinYinArr(arr,11));
				}
			}
			if(StringUtils.isNotEmpty(arr[22])){     // 取ver
				long bbh = getBBH(arr[22]);
				if(bbh > maxVer){
					maxVer = bbh;
					maxVerStr = arr[22];
				}					
			}
		}else if(type.equals("1309")){  // --------------门诊慢特病种目录下载		
			if(StringUtils.isNotEmpty(arr[5]) && "1".equals(arr[5])){   //有效标志为1才插入
				if(isExists("gjyb_mzmtbzml","mmmtbzmldm",arr[0]) == 0){
					if(arr[10].length()>2000){
						arr[10] = arr[10].substring(0, 2000/3);								
					}
					rsfComlfsServiceMapper.insertMztmbzml(getPinYinArr(arr,14));
				}
			}
			if(StringUtils.isNotEmpty(arr[11])){      // 取ver_name
				long bbh = getBBH(arr[11]);
				if(bbh > maxVer){
					maxVer = bbh;
					maxVerStr = arr[11];
				}					
			}
		}else if(type.equals("1310")){  // --------------按病种付费病种目录下载
			if(StringUtils.isNotEmpty(arr[5]) && "1".equals(arr[5])){   //有效标志为1才插入
				if(isExists("gjyb_abzffbzml","bzjsmlid",arr[0]) == 0){
					rsfComlfsServiceMapper.insertAbzffbzml(getPinYinArr(arr,2));
				}
			}
			if(StringUtils.isNotEmpty(arr[12])){      // 取ver_name
				long bbh = getBBH(arr[12]);
				if(bbh > maxVer){
					maxVer = bbh;
					maxVerStr = arr[12];
				}					
			}
		}else if(type.equals("1311")){  // --------------日间手术治疗病种目录下载 
			if(StringUtils.isNotEmpty(arr[3]) && "1".equals(arr[3])){   //有效标志为1才插入
				if(isExists("gjyb_rjsszlbzml","rjsszlmlid",arr[0]) == 0){
					rsfComlfsServiceMapper.insertRjsszlbzml(getPinYinArr(arr,2));
				}
			}
			if(StringUtils.isNotEmpty(arr[10])){      // 取ver_name
				long bbh = getBBH(arr[10]);
				if(bbh > maxVer){
					maxVer = bbh;
					maxVerStr = arr[10];
				}					
			}
		}else if(type.equals("1312")){  // --------------医保目录信息查询
			
		}else if(type.equals("1313")){  // --------------肿瘤形态学目录下载
			if(StringUtils.isNotEmpty(arr[5]) && "1".equals(arr[5])){   //有效标志为1才插入
				if(isExists("gjyb_zlxtxml","zlxtxid",arr[0]) == 0){
					rsfComlfsServiceMapper.insertZlxtxml(getPinYinArr(arr,2));
				}
			}
			if(StringUtils.isNotEmpty(arr[9])){      // 取ver
				long bbh = Long.valueOf(arr[9]);
				if(bbh > maxVer){
					maxVer = bbh;
					maxVerStr = arr[9];
				}					
			}
		}else if(type.equals("1314")){  // --------------中医疾病目录下载
			if(StringUtils.isNotEmpty(arr[8]) && "1".equals(arr[8])){   //有效标志为1才插入
				if(isExists("gjyb_zyjbml","jbdm",arr[0]) == 0){
					rsfComlfsServiceMapper.insertZyjbml(getPinYinArr(arr,6));
				}
			}
			if(StringUtils.isNotEmpty(arr[12])){     // 取ver
				long bbh = Long.valueOf(arr[12]);
				if(bbh > maxVer){
					maxVer = bbh;
					maxVerStr = arr[12];
				}					
			}
		}else if(type.equals("1315")){  // --------------中医证候目录下载
			if(StringUtils.isNotEmpty(arr[8]) && "1".equals(arr[8])){   //有效标志为1才插入
				if(isExists("gjyb_zyzhml","zhdm",arr[0]) == 0){
					rsfComlfsServiceMapper.insertZyzhml(getPinYinArr(arr,6));
				}
			}
			if(StringUtils.isNotEmpty(arr[12])){     // 取ver
				long bbh = Long.valueOf(arr[12]);
				if(bbh > maxVer){
					maxVer = bbh;
					maxVerStr = arr[12];
				}					
			}
		}else if(type.equals("1316")){  // --------------医疗目录与医保目录匹配信息查询
			
		}else if(type.equals("1317")){  // --------------医药机构目录匹配信息查询
			
		}else if(type.equals("1318")){  // --------------医保目录限价信息查询
			
		}else if(type.equals("1319")){  // --------------医保目录先自付比例信息查询
			
		}else if(type.equals("对账")){
			maxVer = 1;
			maxVerStr = "";
		}
		maxVo.setMaxVal(maxVer);
		maxVo.setMaxValStr(maxVerStr);
		return maxVo;
	}
	
	/**
	 * @author : 褚国强
	 * @date 创建时间：2021年12月27日
	 * @Description:   医疗目录查询        更新医保目录先自付比例信息 (1312  1319)
	 * 
	*/
	public void sentJsonService(JSONObject jsonObject,String updateDate,Long startRow) throws Exception {	
		
		String infno = jsonObject.getString("infno");
		
		if(startRow==1 && StringUtils.isEmpty(updateDate)){
			if("1312".equals(infno)){
				updateDate = rsfComlfsServiceMapper.getMaxMlcxUpdate();		
			}else if("1319".equals(infno)){
				updateDate = rsfComlfsServiceMapper.getMaxZfblUpdate();					
			}else{
				return;
			}
			if(StringUtils.isEmpty(updateDate)){
				updateDate = this.updateDate;				
			}
		}
		
		
		String log = "";
		long recordCounts = 0;
		long pages = 0;
		long pageSize = 0;
		long pageNum = 0;
		boolean lastPage = false;
		
		if("1312".equals(infno)){			
			JSONObject ylmlResultJson = this.getYlmlJson(jsonObject, updateDate, startRow.toString(), this.pageSize.toString(), this.admdvs);			
			MlcxDataVo mlcx = (MlcxDataVo)JSONObject.toJavaObject(ylmlResultJson.getJSONObject("output"), MlcxDataVo.class);
			for(MlcxVo vo: mlcx.getData()){
				if("1".equals(vo.getVali_flag())){
					rsfComlfsServiceMapper.insertUpdateMLCX(vo);	
				}				
			}
			log = "1312   医疗目录查询";
			
			recordCounts = mlcx.getRecordCounts();
			pages = mlcx.getPages();
			pageSize = mlcx.getPageSize();
			pageNum = mlcx.getPageNum();
			lastPage = mlcx.isLastPage();
		}else if("1319".equals(infno)){			
			JSONObject zfblResultJson = this.getZfblJson(jsonObject, updateDate, startRow.toString(), this.pageSize.toString(), this.admdvs);
			ZfblDataVo zfblVo = (ZfblDataVo)JSONObject.toJavaObject(zfblResultJson.getJSONObject("output"), ZfblDataVo.class);
			for(ZfblVo vo: zfblVo.getData()){
				rsfComlfsServiceMapper.insertUpdateZFBL(vo);					
			}
			log = "1319   自付比例更新";
			
			recordCounts = zfblVo.getRecordCounts();
			pages = zfblVo.getPages();
			pageSize = zfblVo.getPageSize();
			pageNum = zfblVo.getPageNum();
			lastPage = zfblVo.isLastPage();
		}
		if(startRow==1){
			logger.info(log + "： 总条数 =================" + recordCounts);
			logger.info(log + "： 总页数 =================" + pages);
			logger.info(log + "： 每页尺寸 =================" + pageSize);			
		}
		logger.info(log + "： 当前页 =================" + pageNum);
		
		if(!lastPage){   // 不是最后一页  递归调用
			sentJsonService(jsonObject,updateDate, ++startRow);
		}
		
	}
	
	private JSONObject getYlmlJson(JSONObject jsonObject,String updateDate,String pageNum, String pageSize,String admdvs){
		JSONObject zfblJson = RSFRequestJsonUtil.getZFBLJson(jsonObject, updateDate, pageNum, pageSize, admdvs);
		String returnStr = RsfComIfsService.sentServiceJson(ylmlcxUrl, zfblJson.toJSONString(), requestKey, requestSecret,false);
		JSONObject zfblResultJson =  JSONObject.parseObject(returnStr);
		
		return zfblResultJson;
	}
	
	private JSONObject getZfblJson(JSONObject jsonObject,String updateDate,String pageNum, String pageSize,String admdvs){
		JSONObject zfblJson = RSFRequestJsonUtil.getZFBLJson(jsonObject, updateDate, pageNum, pageSize, admdvs);
		String returnStr = RsfComIfsService.sentServiceJson(zfblUrl, zfblJson.toJSONString(), requestKey, requestSecret,false);
		JSONObject zfblResultJson =  JSONObject.parseObject(returnStr);
		
		return zfblResultJson;
	}
	
	/**
	 * 获取版本号
	*/
	private long getBBH(String bbhStr){
		
		String [] bbhArr = bbhStr.split("_");
		if(bbhArr.length > 2){
			return Long.valueOf(bbhArr[1]);
		}
		
		return Long.valueOf(bbhStr);
	}
	
	/**
	 * 生成带拼音缩写，新数组
	 * @param  原参数组，拼音来源
	*/
	private String[] getPinYinArr(String[] oldArr, int rowNum){
		
		String[] newArr = java.util.Arrays.copyOf(oldArr,oldArr.length + 1);
		
		String pydm = PinyinUtil.getShouZiMuPinyin(oldArr[rowNum]);
		
		if(pydm.length()>10){
			pydm = pydm.substring(0,10);
		}
		
		newArr[oldArr.length] = pydm;
		
		return newArr;
	}
	
	/**
	 * 解压文件夹解析
	 * @param  表名     主键列名   主键
	*/
	private int isExists(String tableName, String colName, String id){
		
		HashMap<String,Object> param = new HashMap<String,Object>();
		param.put("tableName", tableName);
		param.put("colName", colName);
		param.put("id", id);
		
		return rsfComlfsServiceMapper.isExists(param);
	}
	
	/**
	 * 更新最大版本号
	*/
	
	private void updateDownloadVersion(HashMap<String,Object> params){
		HashMap<String,Object> param =new HashMap<String,Object>();
		param.put("tableName", "GY_IDENTITY");
		param.put("colName", "bmc");
		param.put("id", "GY_GJYB_ZDXZ");
		int currentValue = 1;
		int isExists = rsfComlfsServiceMapper.isExists(param);
		if(isExists == 0){
			rsfComlfsServiceMapper.insertGyIdentity();
		}
		
		param =new HashMap<String,Object>();
		param.put("tableName", "GJYB_ZDXZJL");
		param.put("colName", "file_qury_no");
		param.put("id", params.get("fileQuryNo"));
		int isExistsJl = rsfComlfsServiceMapper.isExists(param);
		if(isExistsJl == 0){
			if(isExists != 0){
				rsfComlfsServiceMapper.updateGyIdentity();
				currentValue = rsfComlfsServiceMapper.getJlId(params);	
			}
			
			params.put("currentValue", currentValue);
			
			rsfComlfsServiceMapper.insertDownloadVersion(params);	
		}else{
			rsfComlfsServiceMapper.updateDownloadVersion(params);	
		}
	}
	/**
	 *  获取系统参数值
	*/
	public String getXtCsz(String csmc,String mrz,String bz, int jgid){

		HashMap<String,Object> param = new HashMap<String,Object>();
		param.put("csmc", csmc);
		param.put("mrz", mrz);
		param.put("bz", bz);
		param.put("jgid", jgid);
		String csz = rsfComlfsServiceMapper.getXtCsz(param);
		if(StringUtils.isEmpty(csz)){
			rsfComlfsServiceMapper.insertXTCS(param);	
			return mrz;
		}
		return csz;		
	}
	
	
	
	/**
	 * @author : 褚国强
	 * @date 创建时间：2021年12月27日
	 * @Description:  医疗目录查询
	 * @version 1.0
	 * @parameter
	 * @since
	 * @return
	 */
	public void rsfMlcxService(String parStr) {
		// TODO Auto-generated method stub
		
		RsfComIfsService.sentServiceJson(ylmlcxUrl, parStr, requestKey, requestSecret,true);
	}
	
	/**
	 * @author : 褚国强
	 * @date 创建时间：2022年01月11日
	 * @Description:  解析excel
	 * @version 1.0
	 * @parameter
	 * @since
	 * @return
	 */

	public void rsfUpload(HashMap<String, Object> param) {
		// TODO Auto-generated method stub
		String filename = param.get("fileUrl").toString();
        EasyExcel.read(filename,MlcxVoExcel.class,new ExcelListener(rsfComlfsServiceMapper,param.get("type").toString())).sheet().doRead();
		
	}
	
	
	/**
	 * @author : 褚国强
	 * @date 创建时间：2022年01月11日
	 * @Description:  解析excel
	 * @version 1.0
	 * @parameter
	 * @since
	 * @return
	 */

	public void rsfZfblUpload(HashMap<String, Object> param) {
		// TODO Auto-generated method stub
		String filename = param.get("fileUrl").toString();
        EasyExcel.read(filename,ZfblVoExcela.class,new ZfblExcelListener(rsfComlfsServiceMapper,param.get("type").toString())).sheet().doRead();
		
	}
	
	public static void main(String[] args)  throws Exception{
//		String filename = "C:\\Users\\10268\\Desktop\\三大目录1229\\1312医保目录信息\\耗材-基础 1229.xlsx";
//        EasyExcel.read(filename,MlcxVoExcel.class,new ExcelListener(null,"1")).sheet().doRead();
//		Date now = new Date();
//		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");//可以方便地修改日期格式
//
//
//		String hehe = dateFormat.format( now );
//		
//		System.out.print(hehe);
		
		String zipPath = Decompressing.zipUncompress("C:\\Users\\小手我破的处\\Desktop\\chugiegie\\FYDZ_1642468414663_903.zip");
	}

	/**
	* @author : 褚国强
	* @date 创建时间：2022年1月17日 上午9:09:00
	* @Description: TODO
	* @version 1.0
	* @parameter
	* @since
	* @return
	 * @throws Exception 
	*/
	public String rsfGjybDZ(String parStr) throws Exception {
		// TODO Auto-generated method stub
		File fileDir = new File("\\gjyb_down"); 
		if(!fileDir.exists()){
			fileDir.mkdirs(); 
		}
		
		Random random = new Random(); // 防止狗屎性的同时请求相同名称
		
		String fileName = "费用对账_" + System.currentTimeMillis()+ "_" + random.nextInt(1000) + ".zip";
		
		String filePath = "\\gjyb_down\\" + fileName;
		
		RsfComIfsService.sentService(requestUrl, parStr, filePath, requestKey, requestSecret);
		
		
		String zipPath = Decompressing.zipUncompress(filePath);
		
		readFiles(zipPath,"对账","",fileName, null);
		
		return filePath;
	}
}
